# -*- coding: utf-8 -*-
# @Time    : 2024/12/18 21:24
# @Author  : xiangbo
# @Email   : xiangbo@163.com
# @File    : conftest.py
# @Software: PyCharm
"""
pytest中共享fixture模块
"""
import pytest
import requests

from common.tools import generate_random_string


@pytest.fixture
def token(request):
    # request.param 是由 parametrize 提供的当前参数值
    datas = request.param
    data = {
        "app_key": datas[0],
        "username": datas[1],
        "password": datas[2]
    }
    r = requests.post(datas[3], data=data)
    r = r.json()
    return r.get('data').get('token')


@pytest.fixture
def uuid():
    data = {
        "app_key": "C1312B38C998D18F0A8A501314EE09A1",
        "username": generate_random_string(6),
        "password": "e10adc3949ba59abbe56e057f20f883e"
    }
    r = requests.post("https://hn.api.yesapi.net/?&s=App.User.Register", data=data)
    r = r.json()
    return r.get('data').get('uuid')


@pytest.fixture
def username():
    name = generate_random_string(6)
    data = {
        "app_key": "C1312B38C998D18F0A8A501314EE09A1",
        "username": name,
        "password": "e10adc3949ba59abbe56e057f20f883e"
    }
    requests.post("https://hn.api.yesapi.net/?&s=App.User.Register", data=data)
    return name


@pytest.fixture
def change_user():
    name = generate_random_string(6)
    data = {
        "app_key": "38B9FB99DD25806DCFA5F529F281AB46",
        "username": name,
        "password": "e10adc3949ba59abbe56e057f20f883e"
    }
    requests.post("http://api.yesapi.cn/api/App/User/Register", data=data)
    return name
